---
title: "WhatsApp Image Generation Agent (Model-based)"
description: "WhatsApp agent that generates images using Gemini's built-in capabilities"
---

## Code

```python cookbook/os/interfaces/whatsapp/image_generation_model.py
from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.models.google import Gemini
from agno.os.app import AgentOS
from agno.os.interfaces.whatsapp import Whatsapp

agent_db = SqliteDb(db_file="tmp/persistent_memory.db")
image_agent = Agent(
    id="image_generation_model",
    db=agent_db,
    model=Gemini(
        id="gemini-2.0-flash-exp-image-generation",
        response_modalities=["Text", "Image"],
    ),
    debug_mode=True,
)

agent_os = AgentOS(
    agents=[image_agent],
    interfaces=[Whatsapp(agent=image_agent)],
)
app = agent_os.get_app()

if __name__ == "__main__":
    agent_os.serve(app="image_generation_model:app", reload=True)
```

## Usage

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="Set Environment Variables">
    ```bash
    export WHATSAPP_ACCESS_TOKEN=your_whatsapp_access_token
    export WHATSAPP_PHONE_NUMBER_ID=your_phone_number_id
    export WHATSAPP_WEBHOOK_URL=your_webhook_url
    export WHATSAPP_VERIFY_TOKEN=your_verify_token
    export GOOGLE_API_KEY=your_google_api_key
    export APP_ENV=development
    ```
  </Step>

  <Step title="Install libraries">
    ```bash
    pip install -U agno
    ```
  </Step>

  <Step title="Run Example">
    <CodeGroup>
    ```bash Mac
    python cookbook/os/interfaces/whatsapp/image_generation_model.py
    ```

    ```bash Windows
    python cookbook/os/interfaces/whatsapp/image_generation_model.py
    ```
    </CodeGroup>
  </Step>
</Steps>

## Key Features

- **Direct Image Generation**: Gemini 2.0 Flash experimental image generation
- **Text-to-Image**: Converts descriptions into visual content
- **Multimodal Responses**: Generates both text and images
- **WhatsApp Integration**: Sends images directly through WhatsApp
- **Debug Mode**: Enhanced logging for troubleshooting

